package cn.edu.sgu.www.shiro.controller;

import cn.edu.sgu.www.shiro.dto.UserLoginDTO;
import cn.edu.sgu.www.shiro.restful.JsonResult;
import cn.edu.sgu.www.shiro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author heyunlin
 * @version 1.0
 */
@RestController
@RequestMapping(path = "/user", produces = "application/json;charset=utf-8")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 登录认证
     * @param loginDTO 登录信息
     * @return JsonResult<Void>
     */
    @RequestMapping(path = "/login", method = RequestMethod.POST)
    public JsonResult<Void> login(@Validated UserLoginDTO loginDTO) {
        userService.login(loginDTO);

        return JsonResult.success("登录成功");
    }

    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public JsonResult<Void> delete() {
        return JsonResult.success("删除成功");
    }

    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public JsonResult<Void> update() {
        return JsonResult.success("修改成功");
    }

}